<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言板</title>
    <script src="js/jquery.min.js"></script>
</head>
<style>
    .box{
        width:600px;
        border:1px solid #000;
        margin: 30px auto;
    }
    .box #name{
        width:250px;
    }

    .box .form{
        padding-bottom: 10px;
        border-bottom: solid 5px #00ff00;
    }
    .box form textarea {
      margin: 20px auto;
      margin-left:50px
    }

    #display p {
      padding-left: 40px;
    }
</style>
<body>
    <div class="box">
        <form action="#">
            昵称：<input type="text" id="name" value="">
            <textarea id="text" cols="60" rows="10"></textarea><br>
            <input type="checkbox" name="" id="unname">匿名
            <input type="button" id="btn" value="发表">
        </form>
        <div id="display">

        </div>
    </div>
</body>

<script>
    let unname = false;

    $name = $("#name");
    $text = $("#text");
    $unname = $("#unname");
    $btn = $("#btn");
    $display = $("#display");
    $unname.click(() => {
        unname = !unname;
    })
    $btn.click(function(){
        const name = $name.val();
        const text = $text.val();
        const now = new Date();
        const nowtime = now.getHours() >=12 ? `下午${now.getHours()-12}:${now.getMinutes()}:${now.getSeconds()}`
                        :`上午${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
        
        if(unname){
            $display.append(`<span>路人甲 ${nowtime}<span/><p>${text}</p>`)
        }else{
            $display.append(`<span>${name} ${nowtime}<span/><p>${text}</p>`)
        }
        $name.val("");
        $text.val("");
    });
</script>
</html>